package com.threeonemeeting;

import java.util.ArrayList;

import android.content.Context;

import com.threeonemeeting.db.AppDBHelper;
import com.threeonemeeting.list.CityInfoList;
import com.threeonemeeting.list.DepartmentInfoList;
import com.threeonemeeting.list.EnrollFieldInfoList;
import com.threeonemeeting.list.FullMeetingInfoList;
import com.threeonemeeting.list.MeetingExpressList;
import com.threeonemeeting.list.PosInfoList;
import com.threeonemeeting.list.TradesInfoList;
import com.threeonemeeting.list.UserInfoList;
import com.threeonemeeting.model.DownloadInfoList;
import com.threeonemeeting.model.EnrollFieldName;
import com.threeonemeeting.model.UserInfo;

// 数据中心，存储可能需要的各种数据
public class DataCenter {

	public static final String SINA_CONSUMER_KEY = "4222928934";
	public static final String SINA_CONSUMER_SECRET = "1965acf7be4f5658f949ee2154ce8f77";

	public static final String QQ_CONSUMER_KEY = "6ad6fdb0a1c84834ac006ce41163086d";
	public static final String QQ_CONSUMER_SECRET = "d6edfdb3152f7dd18f6b45af1c761324";

	public Context applicationContext;

	public AppDBHelper db;

	public UserInfo mainLoginUser; // 主账户
	public UserInfo currentLoginUserInfo; // 当前登录的用户
	public UserInfoList listUsers;
	public UserInfoList listAccounts; // 当前登录的用户的信息信息列表

	public FullMeetingInfoList listFullMeeting;
	public DownloadInfoList listDownload;
	public TradesInfoList listTrades;
	public CityInfoList listCity;
	public MeetingExpressList listExpress;

	public ArrayList<EnrollFieldName> listEnrollFieldName;
	public PosInfoList listPosInfo;
	public DepartmentInfoList listDeptInfo;
	public EnrollFieldInfoList listEnrollField; // 报名界面需要的一些字段

	private static DataCenter dataCenter = null;

	public static DataCenter getInstance() {
		if (dataCenter == null) {
			dataCenter = new DataCenter();
			dataCenter.init();
		}

		return dataCenter;
	}

	public AppDBHelper getDB() {
		if (db == null) {
			db = new AppDBHelper(applicationContext);
		}

		return db;
	}

	private DataCenter() {
	}

	private void init() {
		mainLoginUser = new UserInfo();
		currentLoginUserInfo = new UserInfo();
		listUsers = new UserInfoList();
		listAccounts = new UserInfoList();
		listTrades = new TradesInfoList(); // 行业信息
		listCity = new CityInfoList(); // 城市信息

		listFullMeeting = new FullMeetingInfoList();
		listDownload = new DownloadInfoList();
		listExpress = new MeetingExpressList();
		listEnrollField = new EnrollFieldInfoList();

		listEnrollFieldName = new ArrayList<EnrollFieldName>();
		listEnrollFieldName
				.add(new EnrollFieldName(Const.Enroll.RealName, "姓名"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Age, "年龄"));
		listEnrollFieldName
				.add(new EnrollFieldName(Const.Enroll.Email, "Email"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Mobile, "手机"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Phone, "电话"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.MSN, "MSN"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.QQ, "QQ"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.City, "城市"));
		listEnrollFieldName
				.add(new EnrollFieldName(Const.Enroll.Company, "公司"));
		listEnrollFieldName
				.add(new EnrollFieldName(Const.Enroll.Address, "地址"));
		listEnrollFieldName
				.add(new EnrollFieldName(Const.Enroll.Zipcode, "邮编"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Department,
				"职能部门"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.PosStatus,
				"职位级别"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Memo, "其余说明"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Industries,
				"行业"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.BuyCount,
				"报名人数"));
		listEnrollFieldName.add(new EnrollFieldName(Const.Enroll.Fax, "传真"));

		listPosInfo = new PosInfoList();
		listDeptInfo = new DepartmentInfoList();
	}

	public void init(Context ctx) {
		if (ctx == null)
			return;

		Context appContext = ctx.getApplicationContext();
		applicationContext = appContext;

		db = new AppDBHelper(applicationContext);

		listPosInfo.listPosInfo = db.getAllPos();
		listDeptInfo.listDepartmentInfo = db.getAllDepts();
		listTrades = db.getAllTrades();
		listDownload = db.getAllDownloadList();
	}

	public void close() {
		if (db != null && db.isOpen()) {
			db.close();
		}
	}

	public Context getApplicationContext() {
		return applicationContext;
	}
}
